<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Axios 示例</title>
    <!-- 引入 Axios -->
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>Axios 示例</h1>
<div id="result" style="margin-top: 20px;"></div>

<script>
    function getData(){
        axios.get('http://localhost:8080/getUserInfo')
            .then(function (response) {
                // 请求成功处理
                const resultDiv = document.getElementById('result');
                resultDiv.innerHTML = `
                        <h3>响应数据：</h3>
                        <pre>${JSON.stringify(response.data, null, 2)}</pre>
                    `;
            })
            .catch(function (error) {
                // 请求失败处理
                const resultDiv = document.getElementById('result');
                resultDiv.innerHTML = `
                        <h3 style="color: red;">请求错误：</h3>
                        <p>${error.message}</p>
                    `;
            });
    }
    getData();
</script>
</body>
</html>